#include <stdio.h>
#include <string.h>
#include <stdlib.h>

FILE *file_open(const char *path, const char *mode);
int file_close(FILE **fp);

typedef struct Elenemt_data
{
    int id;  // 学号
    int sco; // 成绩
} Elenemt_data;

Elenemt_data HQYJ[5] =
        {
            {.id = 1, .sco = 99},
            {.id = 2, .sco = 98},
            {.id = 3, .sco = 97},
            {.id = 4, .sco = 96},
            {.id = 5, .sco = 95}
        };

int main()
{
    
    //打开文件
    FILE *fp = file_open("731_格式化.txt","r+");

    for(size_t i=0;i<5;i++)
    {
        fprintf(fp,"学号:%d\t成绩:%d\n",HQYJ[i].id,HQYJ[i].sco);
    }

    file_close(&fp);

    return 0;
}

FILE *file_open(const char *path, const char *mode)
{
    FILE *fp = fopen(path, mode);
    if (NULL == fp)
    {
        printf("文件创建失败\n");
        exit(-1);
    }
    return fp;
}

int file_close(FILE **fp)
{
    fclose(*fp);
    *fp = NULL;
}